package cn.edu.scau.cmi.chensicheng.spring.client;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;

import org.springframework.context.ApplicationContext;

import cn.edu.scau.cmi.chensicheng.spring.domain.Student;
import cn.edu.scau.cmi.chensicheng.spring.util.ApplicationContextUtil;
import javafx.application.Application;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.stage.Stage;

public class SpringClient extends Application implements Initializable {
	@FXML
	private Button button;
	@FXML
	private TextArea textArea;

	@Override
	public void start(Stage primaryStage) throws IOException {
		Scene scene = new Scene(FXMLLoader.load(getClass().getResource("../Spring.fxml")));
		primaryStage.setTitle("实验八Spring框架");
		primaryStage.setScene(scene);
		primaryStage.show();

	}

	public static void main(String[] args) {
		launch(args);
	}

	@Override
	public void initialize(URL location, ResourceBundle resources) {
		button.setOnAction(e -> {
			ApplicationContext application = ApplicationContextUtil.getApplicationContext();
			Student student = (Student) application.getBean("chensicheng");
			textArea.setText(student.getTutor().getName());
		});
	}
}
